package com.devmar
{
	import mx.collections.ArrayCollection;
	import com.salesforce.objects.SObject;
	
	[Bindable]
	public class GraphData
	{
		public var partnerOfferingData:ArrayCollection = new ArrayCollection();
		public var offeringRecord:SObject;
		
		public function addInstallData(period:String, value:int):void {
			var podata:PartnerOfferingData = getDataPoint(period);
			if (podata == null) {
				podata = new PartnerOfferingData();
				podata.period = period;
				podata.installCount = value;
				this.partnerOfferingData.addItem(podata);
			} else {
				podata.installCount = value;
			}
		}
		
		public function addLearnMoreData(period:String, value:int):void {
			var podata:PartnerOfferingData = getDataPoint(period);
			if (podata == null) {
				podata = new PartnerOfferingData();
				podata.period = period;
				podata.learnMoreCount = value;
				this.partnerOfferingData.addItem(podata);
			} else {
				podata.installCount = value;
			}
		}

		public function addDemoData(period:String, value:int):void {
			var podata:PartnerOfferingData = getDataPoint(period);
			if (podata == null) {
				podata = new PartnerOfferingData();
				podata.period = period;
				podata.demoCount = value;
				this.partnerOfferingData.addItem(podata);
			} else {
				podata.demoCount = value;
			}
		}
		private function getDataPoint(period:String):PartnerOfferingData {
			for (var i:int=0;i<this.partnerOfferingData.length;i++) {
				var podata:PartnerOfferingData = this.partnerOfferingData[i] as PartnerOfferingData;
				if (podata.period == period) {
					return podata;
				}
			}
			return null;
		}
	}
}